#include<iostream>
using namespace std;
long long f[150][150][150];
long long a[150];
void solve()
{
    int n;
    cin>>n;
    if(n>=120)
    {
        int c;
        while(n--)cin>>c;
        return ;
    }

    for(int i=0;i<=n+10;i++)
        for(int j=0;j<=n+10;j++)
            for(int k=0;k<=n+10;k++)
                {
                    f[i][j][k]=0;
                    a[i]=0;
                }
    int x;
    //f[num][red][blue]
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[i]=x;
        //turn to red
        for(int j=0;j<=i-2;j++)
        {
            //last is red I'm listing where is blue
            f[i][i][j]=max(f[i][i][j],f[i-1][i-1][j]+(a[i]==a[i-1]?a[i]:0));
            //last is blue
            f[i][i][i-1]=max(f[i][i][i-1],f[i-1][j][i-1]+(a[i]==a[j]?a[i]:0));
    //so sadly that I mistake this |up| into f[i][i][j] for 30 mins 
        }

        //f[num][red][blue]

        //turn to blue
        for(int j=0;j<=i-2;j++)
        {
            //last is blue I'm listing where is red
            f[i][j][i]=max(f[i][j][i],f[i-1][j][i-1]+(a[i]==a[i-1]?a[i]:0));
            //last is red
            f[i][i-1][i]=max(f[i][i-1][i],f[i-1][i-1][j]+(a[i]==a[j]?a[i]:0));
        }
        
    }

    int maxx=0;
    for(int i=0;i<=n-1;i++)
    {
        maxx=max(maxx,f[n][i][n]);
        //printf("f[%d][%d][%d]=%d\n",n,i,n,f[n][i][n]);
        maxx=max(maxx,f[n][n][i]);
        //printf("f[%d][%d][%d]=%d\n",n,n,i,f[n][n][i]);
    }

    cout<<maxx<<endl;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--)
    {
        solve();
    }
}